package com.quwan.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.quwan.app.vo.MemberInfoDTO;
import com.quwan.app.vo.MemberShowInfo;
import com.quwan.entity.TMember;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * @author Hayson
 * @since 2021/7/5 23:44
 */
public interface TMemberMapper extends BaseMapper<TMember> {

    @Results({
            @Result(id = true, column = "auto_id", property = "autoId", javaType = Long.class),
            @Result(column = "id", property = "id", javaType = Long.class),
            @Result(column = "nick_name", property = "nickName", javaType = String.class),
            @Result(column = "img_url", property = "imgUrl", javaType = String.class),
            @Result(column = "follower", property = "follower", javaType = Integer.class),
            @Result(column = "follow", property = "follow", javaType = Boolean.class, jdbcType = JdbcType.INTEGER)
    })
    @Select("select m.id,m.auto_id,m.nick_name,m.img_url," +
            "(select count(1) from t_member_follow as f  where f.target_member=m.id and f.status =1) as follower ," +
            "(select count(1) from t_member_follow as a where  un_lock = concat(#{mId} ,m.id) and status =1)  as follow" +
            " from t_member as m  order by follower desc ,follow desc,m.service_level desc  limit 5")
    List<MemberInfoDTO> selectRecommendMember(String mId);

    @Update("update t_member set dd = dd + #{randomDD} where id = #{mId}")
    Integer updateDDBymId(String mId, Integer randomDD);

    @Update("update t_member set android_token ='',ios_token='' where id=#{id} ")
    Integer setDeviceTokenEmpty(String id);

    @Select("select auto_id,m_id,img_url,service_level,gender,nick_name,area from t_member where m_id =#{mId} ")
    MemberShowInfo selectMemberShowInfoById(Long mId);
}